home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / frexxed / fpl / center.fpl < prev    next >
Text File  |  1995-07-18  |  2KB  |  106 lines

  1. /******************************
  2.  * Read Center.FPL.README!    *
  3.  * Written by Daniel Stenberg *
  4.  ******************************/
  5.  
  6. /* We should accept a line number to this function! */
  7. export int CenterLine(int line_number) {
  8.   int lpos;
  9.   int rpos;
  10.   int lcpos;
  11.   int rcpos;
  12.   int max;
  13.   string line;
  14.   int tab = ReadInfo("tab_size");
  15.   int ch;
  16.   int lmargin;
  17.   int left_wall = ReadInfo("wall_left");
  18.   int right_wall = ReadInfo("wall_right");
  19.   int ID = GetEntryID();
  20.   int NewID;
  21.  
  22.   if(!right_wall) {
  23.     ReturnStatus("The 'wall_right' setting must have a non-zero value");
  24.     DisplayBeep();
  25.     return(1);
  26.   }
  27.  
  28.   if(right_wall-left_wall <= 0) {
  29.     ReturnStatus("'wall_right' must be bigger than 'wall_left'");
  30.     return(2);
  31.   }
  32.  
  33.   if(!line_number)
  34.     line_number = ReadInfo("line");
  35.   line = GetLine(line_number);
  36.   max = strlen(line);
  37.  
  38.   for(lpos=0; lpos<max; lpos++) {
  39.     ch = line[lpos];
  40.     if( ch != ' ' && ch != '\t' && ch != '\n') {
  41.       break;
  42.     }
  43.   }
  44.  
  45.   if(lpos<max) {
  46.     if(! (NewID = DuplicateEntry(ID)) ) /* duplicate entry */
  47.       return(4); /* failed */
  48.  
  49.     CurrentBuffer(NewID); /* make the new one the current */
  50.     lcpos = GetCursor(lpos, line_number); /* get column instead of byte position */
  51.     for(rpos=max-1; rpos>=0; rpos--) {
  52.       ch = line[rpos];
  53.       if( ch != ' ' && ch != '\t' && ch != '\n') {
  54.         rpos++; /* get back on the latest whitespace */
  55.         break;
  56.       }
  57.     }
  58.     rcpos = GetCursor(rpos, line_number);
  59.     lmargin = (right_wall - left_wall - rcpos + lcpos)/2;
  60.   
  61.     if(lmargin>=0)
  62.       lmargin += left_wall;
  63.     else
  64.       lmargin = left_wall;
  65.   
  66.     GotoLine(line_number, 0); /* column 0 */
  67.     Delete(lpos);
  68.  
  69.     while(lmargin>tab) {
  70.       Output("\t");
  71.       lmargin-=tab;
  72.     }
  73.  
  74.     while(lmargin--)
  75.       Output(" ");
  76.  
  77.     Kill(NewID);
  78.     CurrentBuffer(ID);
  79.  
  80.   } else
  81.     return(3);
  82.  
  83.   return (0);
  84. }
  85.  
  86. export int CenterBlock()
  87. {
  88.   /* there is a block marked! */
  89.   int start=ReadInfo("block_begin_y");
  90.   int end=ReadInfo("block_end_y");
  91.   int vis = Visible();
  92.   Status(0, "Centering block...");
  93.   Visible(0);
  94.   do {
  95.     CenterLine(start++);
  96.   } while(start<end);
  97.   Visible(vis);
  98.   ReturnStatus("Centering block...done!");
  99. }
  100.  
  101. ConstructInfo("wall_left", "", "", "IL", "", 0, 999, 0);
  102. ConstructInfo("wall_right", "", "", "IL", "", 0, 999, 79);
  103.  
  104. AssignKey("CenterLine(0);", "amiga -", "!block_exist");
  105. AssignKey("CenterBlock();", "amiga -", "block_exist");
  106.